////////////////////////////////////////////////////////////////////////////
//
//  Crytek Engine Source File.
//  Copyright (C), Crytek Studios, 2009.
// -------------------------------------------------------------------------
//  File name:   Wave.cpp
//  Version:     v1.00
//  Created:     2.09.2009 by Evgeny.
//  Compilers:   Visual Studio.NET
//  Description: 
// -------------------------------------------------------------------------
//  History:
//
////////////////////////////////////////////////////////////////////////////

#include "StdAfx.h"
#include "AIWave.h"

#include "AIWavePanel.h"

#include "AI/AIManager.h"


IMPLEMENT_DYNCREATE(CAIWaveObject, CEntityObject)


//////////////////////////////////////////////////////////////////////////
CAIWaveObject::CAIWaveObject()
{
	m_entityClass = "AIWave";
	UseMaterialLayersMask(false);
}

void CAIWaveObject::BeginEditParams(IEditor* ie, int flags)
{
	CBaseObject::BeginEditParams(ie, flags);	// First add standard dialogs

	if (!CEntityObject::m_panel)
	{
		CEntityObject::m_panel = new CAIWavePanel(AfxGetMainWnd());
		CEntityObject::m_panel->Create(CAIWavePanel::IDD, AfxGetMainWnd());
		CEntityObject::m_rollupId = AddUIPage(CString("Entity: ") + m_entityClass, CEntityObject::m_panel);
	}
	if (CEntityObject::m_panel && CEntityObject::m_panel->m_hWnd)
	{
		CEntityObject::m_panel->SetEntity(this);
		static_cast<CAIWavePanel*>(CEntityObject::m_panel)->UpdateAssignedAIsPanel();
	}

	CEntityObject::BeginEditParams( ie,flags ); // At the end add entity dialogs.
}

void CAIWaveObject::BeginEditMultiSelParams(bool bAllOfSameType)
{
	CBaseObject::BeginEditMultiSelParams(bAllOfSameType);

	if (!CEntityObject::m_panel)
	{
		CEntityObject::m_panel = new CAIWavePanel(AfxGetMainWnd());
		CEntityObject::m_panel->Create(CAIWavePanel::IDD, AfxGetMainWnd());
		CEntityObject::m_rollupId = AddUIPage(CString(m_entityClass) + " and other Entities", CEntityObject::m_panel);
	}
	if (CEntityObject::m_panel && CEntityObject::m_panel->m_hWnd)
	{
		static_cast<CAIWavePanel*>(CEntityObject::m_panel)->UpdateAssignedAIsPanel();
	}
}

void CAIWaveObject::EndEditMultiSelParams()
{
	if (m_rollupId != 0)
	{
		RemoveUIPage( m_rollupId );
	}
	m_rollupId = 0;
	m_panel = 0;

	CBaseObject::EndEditMultiSelParams();
}

void CAIWaveObject::SetName(const CString& newName)
{
	CString oldName = GetName();

	__super::SetName(newName);

	GetIEditor()->GetAI()->GetAISystem()->Reset(IAISystem::RESET_INTERNAL);

	GetObjectManager()->FindAndRenameProperty2("aiwave_Wave", oldName, newName);
}
